package com.example.match.camera;


import android.content.Context;
import android.graphics.PixelFormat;
import android.hardware.Camera;
import android.util.AttributeSet;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

import com.example.mylibrary.MyApp;


/**
 * Created by Administrator on 2018/1/24.
 */

public class CameraSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
    public CameraInterface mCameraInterface;
    Context mContext;
    SurfaceHolder mSurfaceHolder;
    private MyApp app;


    public CameraSurfaceView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mContext = context;
        app = MyApp.getInstance();
        mSurfaceHolder = getHolder();
        mSurfaceHolder.setFormat(PixelFormat.TRANSPARENT);
        mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mSurfaceHolder.addCallback(this);
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        CameraInterface.getInstance(mContext).doStopCamera();
        CameraInterface.getInstance(mContext).doOpenCamera(holder,
                Camera.CameraInfo.CAMERA_FACING_BACK);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
        CameraInterface.getInstance(mContext).doStartPreview(mSurfaceHolder,
                1.333f);
    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {
        CameraInterface.getInstance(mContext).doStopCamera();
    }
    public SurfaceHolder getSurfaceHolder() {
        return mSurfaceHolder;
    }
}
